public class asteroid extends entityAbstractObject
{ 
  OBJModel model;
  PApplet appRef;
  
  float rX, rY, rZ; 
  
  asteroid(float x, float y, float vX, float vY, float mass, PApplet appRef)
  {
    super(x,y, vX, vY, mass); 
    
    this.appRef = appRef;
    this.model = new OBJModel(this.appRef);

    this.model.drawMode(POLYGON);
   this.model.load("data/asteroid.obj");
   
   float rangeSpin = 10;
   this.rX = random(-rangeSpin, rangeSpin);
   this.rY = random(-rangeSpin, rangeSpin);
   this.rZ = random(-rangeSpin, rangeSpin);
  }

  public void doCollision(Vector v)
  {
    if(this.mass > 60)
    {
      int pieces = (int)random(4, 15);

      for(int i = 0; i < pieces; i++)
      {
        float x = this.position.x - this.velocity.x;
        float y = this.position.y - this.velocity.y;

        float velX = -this.velocity.x *.8 + random(-1, 1);
        float velY = -this.velocity.y *.8 + random(-1, 1);

        float mass = (this.mass / pieces) * 0.98;

        v.add(new asteroid(x, y, velX , velY, mass, this.appRef)); 
      }
    }
  }

  void draw(float x, float y)
  {
    fill(182, 105, 15);
    stroke(70, 39, 3);
    
    pushMatrix();
      translate(this.position.x + x, this.position.y + y, 0);
    
      rotateX(radians((frameCount/this.rX)%360));
      rotateY(radians((frameCount/this.rY)%360));
      rotateZ(radians((frameCount/this.rZ)%360));
      
      scale(this.rad);  
      this.model.draw();

    popMatrix();
  }
}
